home *** CD-ROM | disk | FTP | other *** search
- Path: tank.news.pipex.net!pipex!iol!usenet
- From: David Byrden <goyra@iol.ie>
- Newsgroups: comp.lang.c++
- Subject: Re: Class constructor usage within another class constructor problem!
- Date: 17 Mar 1996 13:08:46 GMT
- Organization: Ireland On-Line
- Message-ID: <4ih2su$t30@nuacht.iol.ie>
- References: <DoEv3x.IDL@latcs1.lat.oz.au>
- NNTP-Posting-Host: dialup-397.dublin.iol.ie
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 1.22KIT (Windows; I; 16bit)
-
-
- boylesgj@lion.cs.latrobe.edu.au (Gregary J Boyles) wrote:
-
- > Address::Address(int ANumber,const char *AStreet,const char *ACity,int AZip)
- > {
- > Number=ANumber;
- >
- > // *******************************************************************
- > // The next two lines create objects of class String. Do these objects
- > // get placed into the Street and City members of class Address, i.e.
- > // are these lines equivelent to Address.Street=AStreet etc or have I
- > // got it wrong?
- > // *******************************************************************
- > String Street(AStreet);
- > String City(ACity);
-
-
- You've got it wrong. You have created local objects in the function
- block. What you want to do here, is read a C++ book about Constructor
- Initialiser Lists and say
-
- Address::Address(int ANumber,const char *AStreet,
- const char *ACity,int AZip)
- : Street(AStreet), City(ACity)
- {
-
-
-
-
-
- > Address::Address(Address& AnAddress)
- > {
- > Number=AnAddress.Number;
- >
- > // **********************************************************************
- > // Can't pass AnAddress.Street by reference i.e. AnAddress.Street & as
- > // it generates a compile error. Why?
- > // **********************************************************************
- > String Street(AnAddress.Street);
-
-
-
- You DID pass it by reference. At the point where you evaluate the
- parameter, there is no syntactical difference between passing a value and
- a reference. Once again, you need to do some study. Experimenting with
- things you don't understand is a comparatively slow way to learn C++.
-
-
- David :-)
-
-
-